package com.beordie.dao.impl;

import com.beordie.dao.IUserDao;
import com.beordie.model.User;
import com.beordie.utils.DBUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname UserDaoImpl
 * @Description 用户数据库的连接
 * @Date 2021/7/12 20:22
 * @Created 30500
 */
public class UserDaoImpl extends DBUtils implements IUserDao {
    @Override
    public User findUser(String username, String password) {
        List<String> params = new ArrayList<>();
        params.add(username);
        params.add(password);
        User user = null;

        try {
            resultSet = super.query(SQL_SELECT_BY_USERNAME_PASSWORD, params);
            if (resultSet.next()) {
                user = new User();
                user.setId(resultSet.getInt(1));
                user.setUsername(username);
                user.setPassword(password);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            super.closeAll();
        }
        return user;
    }
}
